package xiaohongshu

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"marketing-server/model/common/response"
	"marketing-server/service/marketing/xiaohongshu"
	"net/http"
)

type XhsAuthApi struct{}

// GetAccessToken     // 获取服务商调用凭证 1 有效时间两个小时
// Author [yourname](https://github.com/yourname)
func (xhsAuthApi *XhsAuthApi) GetAccessToken(c *gin.Context) {
	response.OkWithMessage("批量删除成功", c)
}

// GetPreAuthCode     // 获取授权码 2
// Author [yourname](https://github.com/yourname)
func (xhsAuthApi *XhsAuthApi) GetPreAuthCode(c *gin.Context) {
	response.OkWithMessage("批量删除成功", c)
}

// GetTicket     接收ticket推送--验证票据 ticket
// Author [yourname](https://github.com/yourname)
func (xhsAuthApi *XhsAuthApi) GetTicketPublic(c *gin.Context) {
	xhsAuthService := xiaohongshu.XhsAuthService{}
	xhsAuthService.GetTicket(c)
	// 使用 c.Request.URL.Query() 获取所有查询参数

	method := c.Request.Method // 获取请求方法
	if method == http.MethodGet {
		queryParams := c.Request.URL.Query()

		// 将查询参数转换为一个 map[string]string
		result := make(map[string]string)
		for key, values := range queryParams {
			// 只取第一个值
			if len(values) > 0 {
				result[key] = values[0]
			}
		}
		fmt.Println(result)
		response.OkWithMessage("get", c)
		return
	}
	if method == http.MethodPost {
		var jsonData map[string]interface{} // 使用 map 来处理未知结构
		if err := c.ShouldBindJSON(&jsonData); err != nil {
			fmt.Println("POSTERR", err)
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		}
		c.Pos
		fmt.Println(jsonData)
		response.OkWithMessage("post", c)
		return
	}
	response.OkWithMessage("未知", c)
	return
}

// Callback     授权回调
// Author [yourname](https://github.com/yourname)
func (xhsAuthApi *XhsAuthApi) Callback(c *gin.Context) {
	response.OkWithMessage("批量删除成功", c)
}

// Authorization     引导授权
// Author [yourname](https://github.com/yourname)
func (xhsAuthApi *XhsAuthApi) Authorization(c *gin.Context) {
	response.OkWithMessage("批量删除成功", c)
}
